<?php

namespace app\service;

use app\model\MessageTaskConfirmModel;
use app\tool\SingletonTrait;

class TaskStatisticsAbnormalService
{
    use SingletonTrait;

    /**
     * 上游异常通知统计
     * @param array  $param
     * @param string $confirmed
     * @return mixed
     */
    public static function taskUpstreamAbnormalBaseQuery(array $param, string $confirmed = "")
    {
        $dbr = MessageTaskConfirmModel::whereIn('project_id', $param['project_id'])
            ->where('tenant_id', $param['tenant_id'])
            ->whereFieldRaw('array_length(array_intersect(split(link_step_category, ","), ["' . implode('","', $param['step_category_id']) . '"]))', '>', 0)
            ->whereBetween('created', [$param['start_time'], $param['end_time']]);
        if (!empty($confirmed)) {
            $dbr = $dbr->where('confirm', $confirmed);
        }
        return $dbr->count();
    }
}
